package com.yzj.android.dao.impl;

import com.yzj.Bean.Cake;
import com.yzj.android.dao.BaseDao;
import com.yzj.android.dao.CakeDao;

import java.util.List;

public class CakeDaoImpl extends BaseDao implements CakeDao {

    @Override
    public int addCake(Cake cake) {
        String sql = "insert into cake(`name`,`rich`,`price`,`details`,`pic_path`) values(?,?,?,?,?)";
        return update(sql, cake.getName(), cake.getRich(), cake.getPrice(), cake.getDetails(), cake.getPic());
    }
    @Override
    public int deleteCakeById(Integer id) {
        String sql = "delete from cake where id = ?";
        return update(sql, id);
    }
    @Override
    public int updateCake(Cake cake) {
        String sql = "update cake set `name`=?,`rich`=?,`price`=?,`details`=? where id = ?";
        return update(sql, cake.getName(), cake.getRich(), cake.getPrice(), cake.getDetails(), cake.getId());
    }
    @Override
    public Cake queryCakeById(Integer id) {
        String sql = "select `id` , `name` , `rich` , `price` , `details` , `pic_path` pic  from cake where id = ?";
        return queryForOne(Cake.class, sql, id);
    }

    @Override
    public List<Cake> queryCakes() {
        String sql = "select `id` , `name` , `rich` , `price` , `details` , `pic_path` pic  from cake";
        return queryForList(Cake.class,sql);
    }

    @Override
    public List<Cake> queryCake(String name) {

        String sql = "select `id`,`name`,`rich`,`price`,`details`,`pic_path` pic " +
                "from cake where  `name` LIKE concat('%',?,'%')  ";

        return queryForList(Cake.class,sql,name);
    }


}
